package com.liqi.display.controller;


import com.liqi.display.common.Results;
import com.liqi.display.common.SystemCode;
import com.liqi.display.entity.returnType.TotalTakeType;
import com.liqi.display.service.ITblTakeNumberService;
import com.liqi.display.utils.DateUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author liqi
 * @since 2021-04-13
 *
 *取号信息表

 */
@RestController
@RequestMapping("/tbl-take-number")
public class TblTakeNumberController {
    private static Logger logger = LoggerFactory.getLogger(TblTakeNumberController.class);

    @Autowired
    ITblTakeNumberService takeNumberService;

    /**
     * * 取号数汇总：
     * * 1.汇总当天取号数
     * * 2.汇总当月取号数
     * * 3.汇总今年取号数
     *
     * @return
     */
    @RequestMapping("/total")
    public Results total() {
        Results results = new Results();
        try {
            Map<String, Object> map = new HashMap<String, Object>();
            //最近30天的每个时间端（取号数统计=人流量）
            Date late30Date = DateUtil.getLateDate("yyyy-MM-dd HH:mm:ss", 30);
            Map<Object, Object> late30DateMap = new HashMap<Object, Object>();
            late30DateMap.put("9:00~10:00", takeNumberService.lateComare(late30Date, 9));
            late30DateMap.put("10:00~11:00", takeNumberService.lateComare(late30Date, 10));
            late30DateMap.put("11:00~12:00", takeNumberService.lateComare(late30Date, 11));
            late30DateMap.put("14:00~15:00", takeNumberService.lateComare(late30Date, 14));
            late30DateMap.put("15:00~16:00", takeNumberService.lateComare(late30Date, 15));
            late30DateMap.put("16:00~17:00", takeNumberService.lateComare(late30Date, 16));
            late30DateMap.put("17:00~18:00", takeNumberService.lateComare(late30Date, 17));

            //最近7天的每个时间端（取号数统计=人流量）
            Date late7Date = DateUtil.getLateDate("yyyy-MM-dd HH:mm:ss", 7);
            Map<Object, Object> late7DateMap = new HashMap<Object, Object>();
            late7DateMap.put("9:00~10:00", takeNumberService.lateComare(late7Date, 9));
            late7DateMap.put("10:00~11:00", takeNumberService.lateComare(late7Date, 10));
            late7DateMap.put("11:00~12:00", takeNumberService.lateComare(late7Date, 11));
            late7DateMap.put("14:00~15:00", takeNumberService.lateComare(late7Date, 14));
            late7DateMap.put("15:00~16:00", takeNumberService.lateComare(late7Date, 15));
            late7DateMap.put("16:00~17:00", takeNumberService.lateComare(late7Date, 16));
            late7DateMap.put("17:00~18:00", takeNumberService.lateComare(late7Date, 17));

            map.put("30", late30DateMap);
            map.put("7", late7DateMap);
            results.setData(map);
            results.setCode(SystemCode.SYS_OK.getKey());
            results.setMessage(SystemCode.SYS_OK.getValue());
            return results;
        } catch (Exception e) {
            results.setCode(SystemCode.SYS_FAIL.getKey());
            results.setMessage(SystemCode.SYS_FAIL.getValue());
            logger.info("异常信息", e.getMessage());
            return results;
        }
    }

    /**
     * 当前时间取票数与昨日取票数作对比
     *
     * @return
     */
    @GetMapping("compareDay")
    public Results compareDay() {
        Results results = new Results();
        try {
            Map<String, String> compare = takeNumberService.compareDay();
            results.setData(compare);
            results.setCode(SystemCode.SYS_OK.getKey());
            results.setMessage(SystemCode.SYS_OK.getValue());
            return results;
        } catch (Exception e) {
            logger.info("异常信息", e.getMessage());
            results.setCode(SystemCode.SYS_FAIL.getKey());
            results.setMessage(SystemCode.SYS_FAIL.getValue());
            return results;
        }

    }

    @GetMapping("compareMonth")
    public Results compareMonth() {
        Results results = new Results();
        try {
            Map<String, String> compare = takeNumberService.compareMonth();
            results.setData(compare);
            results.setCode(SystemCode.SYS_OK.getKey());
            results.setMessage(SystemCode.SYS_OK.getValue());
            return results;
        } catch (Exception e) {
            logger.info("异常信息", e.getMessage());
            results.setCode(SystemCode.SYS_FAIL.getKey());
            results.setMessage(SystemCode.SYS_FAIL.getValue());
            return results;
        }
    }

   /* @GetMapping("compareYear")
    public Results compareYear(){
        Results results=new Results();
        try {
            Map<String, String> compare = takeNumberService.compareYear();
            results.setData(compare);
            results.setCode(SystemCode.SYS_OK.getKey());
            results.setMessage(SystemCode.SYS_OK.getValue());
            return results;
        }catch (Exception e){
            logger.info("异常信息",e.getMessage());
            results.setCode(SystemCode.SYS_FAIL.getKey());
            results.setMessage(SystemCode.SYS_FAIL.getValue());
            return results;
        }
    }*/

    /**
     * 汇总取号方式
     */
    @RequestMapping("totalTakeType")
    public Results totalTakeType() {
        Results results = new Results();
        try {
            Map<String, Integer> map = takeNumberService.totalTakeType();
            results.setCode(SystemCode.SYS_OK.getKey());
            results.setMessage(SystemCode.SYS_OK.getValue());
            results.setData(map);
            return results;
        } catch (Exception e) {
            results.setCode(SystemCode.SYS_FAIL.getKey());
            results.setMessage(SystemCode.SYS_FAIL.getValue());
            return results;
        }
    }

    /**
     * 汇总现场取号数和预约取号数
     */
    @RequestMapping("/totalCurAndOrd")
    public Results totalCurAndOrd() {
        Results results = new Results();
        try {
            Map<String, Integer> map = takeNumberService.totalOrAndCur();
            results.setCode(SystemCode.SYS_OK.getKey());
            results.setMessage(SystemCode.SYS_OK.getValue());
            results.setData(map);
            return results;
        } catch (Exception e) {
            results.setCode(SystemCode.SYS_FAIL.getKey());
            results.setMessage(SystemCode.SYS_FAIL.getValue());
            return results;
        }
    }

    /**
     * 统计仅七天的预约取号数
     * @return
     */
    @RequestMapping("totalSevenOrder")
    public Results totalSevenOrder() {
        Results results = new Results();
        try {
            Map<String, Integer> map = takeNumberService.totalLateOrder();
            results.setCode(SystemCode.SYS_OK.getKey());
            results.setMessage(SystemCode.SYS_OK.getValue());
            results.setData(map);
            return results;
        } catch (Exception e) {
            results.setCode(SystemCode.SYS_FAIL.getKey());
            results.setMessage(SystemCode.SYS_FAIL.getValue());
            return results;
        }
    }

    /**
     * 统计仅七天的现场取号数
     * @return
     */
    @RequestMapping("totalSevenCurrent")
    public Results totalSevenCurrent() {
        Results results = new Results();
        try {
            Map<String, Integer> map = takeNumberService.totalLateCurrent();
            results.setCode(SystemCode.SYS_OK.getKey());
            results.setMessage(SystemCode.SYS_OK.getValue());
            results.setData(map);
            return results;
        } catch (Exception e) {
            results.setCode(SystemCode.SYS_FAIL.getKey());
            results.setMessage(SystemCode.SYS_FAIL.getValue());
            return results;
        }
    }
}
